package com.ruoyi.common.onlyLetter;

import com.ruoyi.common.utils.StringUtils;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class OnlyLetterValidator implements  ConstraintValidator<OnlyLetter, String>
{
    private final String HTML_PATTERN = "^[A-Za-z]+$";

    @Override
    public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext)
    {
        if(StringUtils.isBlank(value)){
            return false;
        }
        return containsHtml(value);
    }

    public boolean containsHtml(String value)
    {
        Pattern pattern = Pattern.compile(HTML_PATTERN);
        Matcher matcher = pattern.matcher(value);
        return matcher.matches();
    }
}
